<!--
 * @Author: Wangtao
 * @Date: 2022-04-21 21:01:54
 * @LastEditors: Wangtao
 * @LastEditTime: 2022-04-21 21:19:31
-->
<template>
  <configTable
    ref="table"
    :data="logData"
    :headersConfig="false"
    :pagingData="pagingData"
    @pageChange="handleCurrentChange"
    @pageSizeChange="handleSizeChange"
  >
    <template slot="column">
      <template v-for="(item, index) in checkHeaders">
        <u-table-column
          :key="index"
          :label="item.label"
          :prop="item.prop"
          :resizable="true"
          :show-overflow-tooltip="true"
        >
        </u-table-column>
      </template>
    </template>
  </configTable>
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'
import configTable from '@/components/globalTool/resizeTable/index.vue'
import { commonAction } from '@/utils/common'
import { CommonModule } from '@/store/modules/common'
@Component({
  name: 'qualityLog',
  components: {
    configTable
  }
})
export default class QualityLog extends Vue {
  [x: string]: any
  @Prop() private chatSessionId
  private logData: any = []
  private pagingData = { total: 0, limit: 10, page: 1 }
  private checkHeaders = [
    {
      label: '人员',
      prop: 'qualityName'
    },
    {
      label: '时间',
      prop: 'qualityStatusTime'
    },
    {
      label: '操作',
      prop: 'qualityStatusDetail'
    }
  ]

  private handleSizeChange (size: number) {
    this.pagingData.limit = size
    this.getLogData()
  }

  private handleCurrentChange (page: number) {
    this.pagingData.page = page
    this.getLogData()
  }

  private getAgentName (agentId) {
    const agent = (CommonModule as any).publicCache.userListObj[agentId]
    if (agent) {
      return agent.name
    }
    return '--'
  }

  public async getLogData () {
    const sendData = {
      page: this.pagingData.page,
      limit: this.pagingData.limit,
      qualitySessionId: this.chatSessionId
    }
    const res: any = await commonAction({ url: '/im-center/action/quality/queryQualityLog', method: 'POST', data: sendData })
    if (res.success && res.data) {
      this.logData = res.data.list.map(item => {
        item.qualityLog.qualityName = this.getAgentName(item.qualityLog.qualityUser)
        return item.qualityLog
      })
      this.pagingData.total = res.data.count
    }
  }
}
</script>
<style lang="stylus" scoped>
.resize-table
  padding 0 24px
</style>
